using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Condimar.Entities;

namespace Condimar.Repository.Mapping
{
    public class CompraMap : EntityTypeConfiguration<Compra>
    {
        public CompraMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Total)
                .IsFixedLength()
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Compra");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ProveedorId).HasColumnName("ProveedorId");
            this.Property(t => t.ProductoId).HasColumnName("ProductoId");
            this.Property(t => t.Fecha).HasColumnName("Fecha");
            this.Property(t => t.Total).HasColumnName("Total");

            // Relationships
            this.HasOptional(t => t.Proveedor)
                .WithMany(t => t.Compras)
                .HasForeignKey(d => d.ProveedorId);

        }
    }
}
